package com.example.controller;

import com.example.Application;
import com.example.dto.SmsCodeResquest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 演示Spring Boot核心概念的测试Controller
 * 
 * 🎯 这个Controller演示了：
 * 1. @ComponentScan自动扫描功能
 * 2. @Autowired依赖注入
 * 3. 自动配置的Web MVC功能
 */
@Tag(name = "演示接口", description = "Spring Boot 核心概念演示接口")
@RestController
@RequestMapping("/api/demo")
public class DemoController {

    /**
     * 注入我们在Application中定义的AppInfo Bean
     * 演示@Configuration功能和依赖注入
     */
    @Autowired
    private Application.AppInfo appInfo;

    /**
     * 演示接口：获取应用信息
     * 
     * 🔍 这个接口展示了Spring Boot的多个核心概念：
     * - @RestController由@ComponentScan扫描并注册
     * - Web MVC功能由@EnableAutoConfiguration自动配置
     * - AppInfo Bean由@Configuration功能创建
     */
    @Operation(summary = "获取应用信息", description = "演示 Spring Boot 三合一注解功能，获取应用基本信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功")
    })
    @GetMapping("/info")
    public Map<String, Object> getAppInfo() {
        System.out.println("📞 DemoController.getAppInfo() 被调用");
        System.out.println("🔗 注入的AppInfo: " + appInfo);
        
        Map<String, Object> result = new HashMap<>();
        result.put("name", appInfo.getName());
        result.put("version", appInfo.getVersion());
        result.put("description", appInfo.getDescription());
        result.put("message", "Spring Boot三合一注解功能演示成功！");
        
        return result;
    }

    /**
     * 演示接口：Spring Boot特性说明
     */
    @Operation(summary = "获取 Spring Boot 特性", description = "详细说明 @SpringBootApplication 三合一注解的功能")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功")
    })
    @GetMapping("/features")
    public Map<String, Object> getFeatures() {
        System.out.println("📞 DemoController.getFeatures() 被调用");
        
        Map<String, Object> features = new HashMap<>();
        features.put("@Configuration", "✅ 可以定义Bean (如AppInfo)");
        features.put("@EnableAutoConfiguration", "✅ 自动配置Web MVC, Jackson, 数据源等");
        features.put("@ComponentScan", "✅ 自动扫描Controller, Service, Repository等");
        features.put("总结", "一个@SpringBootApplication = 三个注解功能");
        
        return features;
    }

}
